package com.youle.robots.message;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Destination;

/**
 * 消息生产者
 * Created by IntelliJ IDEA.
 * User: kedong
 * Date: 18-3-27
 * Time: 下午3:02
 * To change this template use File | Settings | File and Code Templates ->Includes->File Header.
 *
 * @author kedong
 */
@Service
public class Producer {

    // 也可以注入JmsTemplate，JmsMessagingTemplate对JmsTemplate进行了封装
    @Autowired
    private JmsMessagingTemplate jmsTemplate;

    // 发送消息，destination是发送到的队列，message是待发送的消息
    public void sendMessage(Destination destination, final String message) {
        System.out.println("发送消息：" + message);
        jmsTemplate.convertAndSend(String.valueOf(destination), message);
    }

    @JmsListener(destination="out.queue")
    public void consumerMessage(String text){
        System.out.println("从out.queue队列收到的回复报文为:"+text);
    }

}
